<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    
const data = [
  {
    "id":1,
    "parent_id":0,
    "name":"四川省",
    "children":[
      {
        "id":5,
        "parent_id":1,
        "name":"成都市",
        "children":[
          {
            "id":6,
            "parent_id":5,
            "name":"锦江区",
            "children":[
              {
                "id":7,
                "parent_id":6,
                "name":"九眼桥"
              },
              {
                "id":8,
                "parent_id":6,
                "name":"兰桂坊"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "id":2,
    "parent_id":0,
    "name":"广东省",
    "children":[
      {
        "id":9,
        "parent_id":2,
        "name":"东莞市",
        "children":[
          {
            "id":10,
            "parent_id":9,
            "name":"长安镇"
          }
        ]
      }
    ]
  },
  {
    "id":3,
    "parent_id":0,
    "name":"江西省",
    "children":[
      {
        "id":11,
        "parent_id":3,
        "name":"南昌市"
      }
    ]
  }
]

const results = []

function srotData(data, province) {
  if (data instanceof Array) {
    data.forEach(item => {
      if (province) {
        province.children.push({
          id: item.id,
          parent_id: item.parent_id,
          name: item.name
        })
        if (item.children && item.children.length) {
          srotData(item.children, province)
        }
      } else {
        const _province = {
          id: item.id,
          parent_id: item.parent_id,
          name: item.name
        }
        if (item.children && item.children.length) {
          _province.children = _province.children || []
          srotData(item.children, _province)
        }
        results.push(_province)
      }  
    })
  }
  return results
}
console.log(srotData(data))
  </script>
</body>
</html>